home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- '''
- '''
- __author__ = 'Robert Ancell <bob27@users.sourceforge.net>'
- __license__ = 'GNU General Public License Version 2'
- __copyright__ = 'Copyright 2005-2006 Robert Ancell'
- import glchess.scene as glchess
-
- class SceneHumanInput:
- '''
- '''
- __inputEnabled = True
- __startSquare = None
- __showHints = True
-
- def __init__(self):
- '''Constructor for a scene with human selectable components'''
- pass
-
-
- def onRedraw(self):
- '''This method is called when the scene needs redrawing'''
- pass
-
-
- def playerIsHuman(self):
- '''Check if the current player is a human.
-
- Return True the current player is human else False.
- '''
- return False
-
-
- def getSquare(self, x, y):
- """Find the chess square at a given 2D location.
-
- 'x' is the number of pixels from the left of the scene to select.
- 'y' is the number of pixels from the bottom of the scene to select.
-
- Return the co-ordinate as a tuple in the form (file,rank) or None if
- no square at this point.
- """
- pass
-
-
- def squareIsFriendly(self, coord):
- '''Check if a given square contains a friendly piece.
-
- Return True if this square contains a friendly piece.
- '''
- return False
-
-
- def canMove(self, start, end):
- """Check if a move is valid.
-
- 'start' is the location to move from in LAN format (string).
- 'end' is the location to move from in LAN format (string).
- """
- return False
-
-
- def moveHuman(self, start, end):
- """Called when a human player moves.
-
- 'start' is the location to move from in LAN format (string).
- 'end' is the location to move from in LAN format (string).
- """
- pass
-
-
- def enableHumanInput(self, inputEnabled):
- """Enable/disable human input.
-
- 'inputEnabled' is a flag to show if human input is enabled (True) or disabled (False).
- """
- if inputEnabled is False:
- self._SceneHumanInput__selectSquare(None)
-
- self._SceneHumanInput__inputEnabled = inputEnabled
-
-
- def select(self, x, y):
- '''
- '''
- if self._SceneHumanInput__inputEnabled is False:
- return None
- if self.playerIsHuman() is False:
- return None
- coord = self.getSquare(x, y)
- if coord is None:
- return None
- if self._SceneHumanInput__startSquare == coord:
- self._SceneHumanInput__selectSquare(None)
- return None
- if self.squareIsFriendly(coord):
- self._SceneHumanInput__selectSquare(coord)
- elif self._SceneHumanInput__startSquare is not None:
- self._SceneHumanInput__move(self._SceneHumanInput__startSquare, coord)
-
- self.onRedraw()
- return coord
-
-
- def deselect(self, x, y):
- '''
- '''
- if self._SceneHumanInput__inputEnabled is False:
- return None
- if self.playerIsHuman() is False:
- return None
- coord = self.getSquare(x, y)
- if coord is None:
- return None
- self.onRedraw()
- return coord
-
-
- def __selectSquare(self, coord):
- if self._SceneHumanInput__startSquare == coord:
- return None
- self._SceneHumanInput__startSquare = coord
- self.selectSquare(coord)
-
-
- def __move(self, start, end):
- '''Attempt to make a move.
-
- ...
- '''
- if self.canMove(start, end) is False:
- return None
- self._SceneHumanInput__selectSquare(None)
- self.moveHuman(start, end)
-
-
-